<?php

namespace App\Task\Update;

use App\Model\UserProfile;
use Hyperf\Crontab\Annotation\Crontab;

/**
 * 定时修改在线状态
 * @Crontab(name="UpdateOnlineStatusTask", rule="15,35,55 *\/1 * * *", callback="execute", memo="定时修改在线状态", singleton=true)
 */
class UpdateOnlineStatusTask
{
    public function execute()
    {
        $offHour = env('UPDATE_ONLINE_HOUR', 4);
        $offTime = date('Y-m-d H:i:s', time() - $offHour * 3600);
        $nowTime = date('Y-m-d H:i:s');
        $where = [
            ['online', 1],
            ['updated_at', '<', $offTime],
        ];
        $ret = UserProfile::where($where)->update(['online' => 0]);
        log_info(__CLASS__ . "==Result:{$ret}==OffTime:{$offTime}==UpdateAt:{$nowTime}");
    }
}
